//
//  LXTeamCell.m
//  绿稀全球购
//
//  Created by 王敏 on 16/7/24.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "LXTeamCell.h"
@interface LXTeamCell()

@property(nonatomic,strong)UIView * underLine;
@end
@implementation LXTeamCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
       
        self.cellHeight = 65;
        UIImageView * userIcon = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.userIcon = userIcon;
        [self.contentView addSubview:userIcon];
        
        
        
        UILabel * nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        nameLabel.textAlignment = NSTextAlignmentLeft;
        self.nameLabel = nameLabel;
        nameLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:nameLabel];
        nameLabel.text = @"善觉堂";
        
        UILabel * subUser = [[UILabel alloc] initWithFrame:CGRectZero];
        subUser.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:subUser];
        self.subUser = subUser;
        subUser.text = @"粉丝120人";
        
        
        UIImageView * backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(globalMargin, 0, ScreenWidth-2*globalMargin, self.cellHeight)];
        
        [self.contentView insertSubview:backgroundImageView atIndex:0];
        
        self.backgroundImageView = backgroundImageView;
        
        
        UIView * underLine = [[UIView alloc] initWithFrame:CGRectMake(2*globalMargin, self.cellHeight - 1, ScreenWidth-4*globalMargin, 1)];
        underLine.backgroundColor =HexColor(@"#EEEEEE");
        [self.contentView addSubview:underLine];
        self.underLine = underLine;
        self.enableUnderLine = NO;
        
    }
    return self;
}


-(void)setModel:(id)model
{

    [self setNeedsLayout];
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    self.userIcon.x = 10+globalMargin;
    self.userIcon.y = 10;
    self.userIcon.height = self.cellHeight - 20;
    self.userIcon.width = self.userIcon.height;
    [self.userIcon addRadius:self.userIcon.height * 0.5];
    self.userIcon.image = [UIImage imageWithColor:RandColor size:self.userIcon.size];
    
    self.nameLabel.x = (!self.userIcon.hidden)?self.userIcon.right + 10:2*globalMargin;
    self.nameLabel.centerY = self.cellHeight * 0.5;
    self.nameLabel.width = [self.nameLabel.text sizeInAre:MaxSize font:self.nameLabel.font].width;
    self.nameLabel.height = [self.nameLabel.text sizeInAre:MaxSize font:self.nameLabel.font].height;
    
    self.subUser.size = [self.subUser.text sizeInAre:MaxSize font:self.subUser.font];
    self.subUser.x = ScreenSize.width-4*globalMargin - self.subUser.width;
    self.subUser.centerY = self.cellHeight * 0.5;
    self.subUser.hidden = !self.showSubTeam;
    
    self.accessoryType = self.showSubTeam?UITableViewCellAccessoryDisclosureIndicator:UITableViewCellAccessoryNone;
    
    self.backgroundImageView.height = self.cellHeight;
    if(self.userIcon.hidden){
//        self.accessoryType =UITableViewCellAccessoryNone;
    }
}

-(void)setBackgroundImage:(UIImage *)backgroundImage{
    _backgroundImage = backgroundImage;
    self.backgroundImageView.image = _backgroundImage;
}

-(void)setEnableUnderLine:(BOOL)enableUnderLine{
    _enableUnderLine = enableUnderLine;
    self.underLine.hidden = !_enableUnderLine;
}
@end
